package com.itheima.mybatis02.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.mybatis01.bean.Teacher;
import com.itheima.mybatis02.service.TeacherService;
import com.itheima.mybatis02.service.TeacherServiceImpl;
import org.junit.Test;

import java.util.List;

public class TeacherController {
    private static TeacherService ts = new TeacherServiceImpl();
    @Test
    public void selectAll() {
        List<Teacher> list = ts.selectAll();
        for (Teacher teacher : list) {
            System.out.println(teacher);
        }
        PageInfo<Teacher> info = new PageInfo<>(list);
        System.out.println("总条数"+info.getTotal());
        System.out.println("总页数"+info.getPages());
        System.out.println("当前页"+info.getPageNum());
    }
    @Test
    public void selectOne() {
        Teacher teacher = ts.selectOne(3);
        System.out.println(teacher);
    }
    @Test
    public void insert() {
        Teacher teacher = new Teacher(9, "hahha", 51);
        int insert = ts.insert(teacher);
        if (insert > 0) {
            System.out.println("添加成功!");
        } else {
            System.out.println("添加失败!");
        }
    }
    @Test
    public void update() {
        Teacher teacher = new Teacher(9, "张大春", 24);
        int update = ts.update(teacher);
        if (update > 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }
    @Test
    public void delete(){
        int delete = ts.delete(9);
        System.out.println(delete);
    }
}
